<script setup lang="ts">
import {RouterLink, RouterView} from "vue-router";
import {useStore} from "@/store";
import {onMounted,provide} from "vue";

const store = useStore();
provide('store', store)
onMounted(() => {
  store.dispatch("updateCartCount");
});
</script>

<template>
<!--  <RouterView/>-->
    <router-view v-slot="{ Component }">
      <transition>
        <keep-alive>
          <component :is="Component" />
        </keep-alive>
      </transition>
    </router-view>
  <div id="nav">
    <RouterLink class="tab-bar-item" to="/">
      <div class="icon">
        <i class="iconfont icon-yemian-copy-copy"></i>
      </div>
      <div>首页</div>
    </RouterLink>
    <RouterLink class="tab-bar-item" to="/category">
      <div class="icon">
        <i class="iconfont icon-fenlei"></i>
      </div>
      <div>分类</div>
    </RouterLink>
    <RouterLink class="tab-bar-item" to="/shopcart">
      <div class="icon">
        <van-badge :content="store.state.cartCount" max="10">
          <i class="iconfont icon-gouwuche"></i>
        </van-badge>
      </div>

      <div>
        购物车
      </div>
    </RouterLink>
    <RouterLink class="tab-bar-item" to="/profile">
      <div class="icon">
        <i class="iconfont icon-gerenzhongxin1"></i>
      </div>
      <div>
        我的
      </div>
    </RouterLink>
  </div>
</template>

<style lang="scss">
@import '@/assets/css/base.css';
@import '@/assets/css/icon/iconfont.css';

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  background-color: #f6f6f6;
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  box-shadow: 0 -3px 1px rgb(100, 100, 100, 0.1);

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: hsla(160, 100%, 37%, 1);
    }
  }

  .tab-bar-item {
    flex: 1;
    text-align: center;
    height: 60px;
    display: flex;
    align-items: center;
    flex-direction: column;
  }

  .tab-bar-item .icon {
    width: 24px;
    height: 24px;
    margin-top: 4px;

  }
}


</style>
